﻿@model Zor_Web.Models.Base.V_InvoiceRemake
@using Webdiyer.WebControls.Mvc;
@using Zor_Tools;
@{
    Layout = null;
}
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>发票号重录</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script language='javascript' src='~/Content/layer/layer.js'></script>
    <!-- 日期选择器 -->
    <script src="~/Content/laydate/laydate.js"></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
    <link href="~/Content/HPlus/css/style.min862f.css" rel="stylesheet" />
    <!-- 打印单样式 -->
    <style type="text/css">
        .p1 {
            font: 12px '新宋体';
            position: absolute;
            top: 415px;
            left: 540px;
        }

        .p2 {
            font: 12px '新宋体';
            position: absolute;
            top: 440px;
            left: 540px;
        }

        .p3 {
            font: 12px '新宋体';
            position: absolute;
            top: 465px;
            left: 540px;
        }
        .In_Numberx {
            font: 25px '微软雅黑';
            color: #FF5722;
        }
    </style>
</head>
<body class="gray-bg">
    <!-- 打印模态 -->
    <div hidden class="content">
        <div id="modalPrint">

            <p class="p1">
                <label id="In_Number_1"></label>
            </p>
            <p class="p2">
               <label id="In_Number_2"></label>
            </p>
            <p class="p3">
               <label id="In_Number_3"></label>
            </p>
        </div>
    </div>
    <div hidden class="content" align="center" aria-hidden="true" data-backdrop="static">
        <div id="modalPrint">
            <p class="h1" align="center">
                汇总单
            </p>
            <p class="p2" align="left">
                汇总部门：<label class="label1" id="Dt_Name"> </label>
                份数：<label class="label1" id="Copies"> </label>
            </p>
            <p class="p2" align="left">
                总金额：<label class="label1" id="SumMoney"> </label>
                汇总时间：<label class="label1" id="Sm_Date"> </label>
            </p>

            <div class="ibox-content">

                <div class="row">
                    <div class="col-sm-6">
                        <div class="ibox float-e-margins">

                            <div class="ibox-content">

                                <table class="table table-bordered">

                                    <thead>
                                        <tr>
                                            <th hidden></th>
                                            <th>序号</th>
                                            <th>受理单号</th>
                                            <th>身份证号</th>
                                            <th>纳税人</th>
                                            <th>完税证号</th>
                                            <th>开票日期</th>
                                            <th>房产税</th>
                                            <th>个人所得税</th>
                                            <th>税额</th>
                                        </tr>
                                    </thead>
                                    <tbody id="accordiondPrint"></tbody>
                                </table>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="col-sm-12 ct-padding">
            <div class=" mail-search">
                <div class="input-group">
                    @*<label class="pull-left">受理单号：</label>*@
                    <input id="where" type="text" class="form-control" placeholder="请输入受理单号" style="width:200px;height:30px">
                    <span class="input-group-btn" style="padding-left:10px">
                        <button id="btnSearch" class="layui-btn  layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-search"></span> 查询</button>
                        <button id="btnPrint" class="layui-btn  layui-btn-steelblue  layui-btn-small"><span class="glyphicon glyphicon-print"></span> 打印</button>
                        <button id="btnInvoice" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 重录发票号</button>
                        <button id="btnRefresh" class="layui-btn layui-btn-blue layui-btn-small"><span class="glyphicon glyphicon-repeat"></span> 刷新</button>
                    </span>
                </div>
            </div>
        </div>

        <div class="layui-tab-content">
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                        <th hidden></th>
                        <th></th>
                        <th>完税证号</th>
                        <th>受理单号</th>
                        <th>受理状态</th>
                        <th>付款人</th>
                        <th>纳税人</th>
                        <th>面积(㎡)</th>
                        <th>租金</th>
                        <th>联系方式</th>
                        <th>发票编号</th>
                        <th>税金</th>
                        <th>开票人</th>
                    </tr>
                </thead>
                <tbody id="accordiond">
                    @foreach (var item in Model.PageData)
                    {
                        <tr hidden>
                            <td hidden>@item.Acceptance_TicketNumber</td>
                            <td><input type="radio" name="chk" id="@item.Acceptance_TicketNumber" value="@item.Acceptance_TicketNumber" /></td>
                            <td>@item.Pt_CertificateNumber</td>
                            <td>@item.Acceptance_TicketNumber</td>   
                            <td>@item.DnState</td>
                            <td>@item.Tenant_Name</td>
                            <td>@item.NatPer_Name</td>
                            <td>@item.Hs_Proportion</td>
                            <td>@item.EReviewRent</td>
                            <td>@item.NatPer_Phone</td>
                            @if (@item.In_ThreeNumber != null)
                            {
                                <td>@item.In_ThreeNumber</td>
                            }
                            else if (@item.In_TwoNumber != null)
                            {
                                <td>@item.In_TwoNumber</td>
                            }
                            else if (@item.In_NewNumber != null)
                            {
                                <td>@item.In_NewNumber</td>
                            }
                            else if (@item.In_Number != null)
                            {
                                <td>@item.In_Number</td>
                            }
                            <td>@item.PtActualTax</td>
                            <td>@item.InUser</td>

                        </tr>
                    }
                </tbody>
            </table>
       
        </div>
    </div>
    <!-- 重录发票号模态 -->
    <div id="myModal" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form method="get" class="form-horizontal m-t">
                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">Id：</label>
                    <div class="col-sm-9">
                        <input id="In_Id" type="text" class="form-control">

                    </div>
                </div>
                <div class="layui-form-item" id="divAt_StreetName">
                    <label class="col-sm-2 layui-form-label">
                        <nobr>发票号码：</nobr>
                    </label>
                    <div class="col-sm-10">
                        <input id="In_Number" type="text" class="form-control" autofocus="autofocus">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">完税证号：</label>
                    <div class="col-sm-4">
                        <input id="Pt_CertificateNumber" type="text" class="laydate-icon  form-control layer-date" readonly="readonly">
                    </div>
                    <label class="col-sm-2 layui-form-label">受理单号：</label>
                    <div class="col-sm-4">
                        <input id="Acceptance_TicketNumber" type="text" class="laydate-icon form-control layer-date" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">付款人：</label>
                    <div class="col-sm-4">
                        <input id="Tenant_Name" type="text" class="form-control" readonly="readonly">
                    </div>
                    <label class="col-sm-2 layui-form-label">业主姓名：</label>
                    <div class="col-sm-4">
                        <input id="NatPer_Name" type="text" class="form-control" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-2 layui-form-label">房屋面积(㎡)：</label>
                    <div class="col-sm-4">
                        <input id="Hs_Proportion" type="text" class="form-control" readonly="readonly">
                    </div>
                    <label class="col-sm-2 layui-form-label">租金（元）：</label>
                    <div class="col-sm-4">
                        <input id="EReviewRent" type="text" class="form-control" readonly="readonly">
                    </div>
                </div>
            </form>
            <div class="form-group">
                <div class="box-footer">
                    <button id="btnSure" class="btn btn-info  pull-right">
                        <i class="fa fa-check"></i>提交
                    </button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script>
    /** 获取发票号 */
    var html1 = "";
    var html2 = "";
    var html3 = "";
    function Invoice_Get() {
        var In_Id = getTableCell(0);
      
        getAjax("/Base/Invoice_Get", { 'In_Id': In_Id }, function (data) {
            var accordionJson = eval(data);
            $.each(accordionJson, function (i) {
                html1 = accordionJson[i].In_NewNumber;
                html2 = accordionJson[i].In_TwoNumber;
                html3 =  accordionJson[i].In_ThreeNumber;
            });
            return;
        })
    }
    /** 更改发票号 */
    function Invoice_New() {
        Invoice_Get();
        var In_Id = getTableCell(0);
        var InNumBer = $("#In_Number").val();
        if (html1 == null) {                 //如果需更改的发票号为空，即更改
            getAjax("/Base/Invoice_New", { 'InNumBer': InNumBer, 'In_Id': In_Id }, function (data) {
                layer.msg("第一次修改成功！",0);
                return;
            })         
        }
        else if (html2 == null) {
            getAjax("/Base/Invoice_Two", { 'InNumBer': InNumBer, 'In_Id': In_Id }, function (data) {
                layer.msg("第二次修改成功！", 0);
                return;
            })
        }
        else if (html3 == null) {
            getAjax("/Base/Invoice_Three", { 'InNumBer': InNumBer, 'In_Id': In_Id }, function (data) {
                layer.msg("第三次修改成功！", 0);
                return;
            })
        }
        else {
            layer.msg("发票号更改已超过三次，请勿继续更改！");
        }
    }
    /** 更改后发票号列表 */
    $(function () {
        $("#btnSure").click(function () {
            Invoice_New();
            var html = "";
            var In_Id = getTableCell(0);
            getAjax("/Base/Update_Invoice", {'In_Id': In_Id }, function (data) {
                var accordionJson = eval(data);
                $.each(accordionJson, function (i) {
                    html += "<tr>";
                    html += "<td hidden>" + accordionJson[i].In_Id + "</td>";
                    html += "<td><input type='checkbox' name='chk' id='" + accordionJson[i].In_Id + "' value='" + accordionJson[i].In_Id + "' ></td>";
                    html += "<td>" + accordionJson[i].Pt_CertificateNumber + "</td>";
                    html += "<td>" + accordionJson[i].Acceptance_TicketNumber + "</td>";
                    html += "<td>" + accordionJson[i].DnState + "</td>";
                    html += "<td>" + accordionJson[i].Tenant_Name + "</td>";
                    html += "<td>" + accordionJson[i].NatPer_Name + "</td>";
                    html += "<td>" + accordionJson[i].Hs_Proportion + "</td>";
                    html += "<td>" + accordionJson[i].EReviewRent + "</td>";
                    html += "<td>" + accordionJson[i].NatPer_Phone + "</td>";
                    if(accordionJson[i].In_ThreeNumber != null){
                        html += "<td>" + accordionJson[i].In_ThreeNumber + "</td>";
                    }
                    else if (accordionJson[i].In_TwoNumber != null) {
                        html += "<td>" + accordionJson[i].In_TwoNumber + "</td>";
                    }
                    else if (accordionJson[i].In_NewNumber != null) {
                        html += "<td>" + accordionJson[i].In_NewNumber + "</td>";
                    }
                    else if (accordionJson[i].In_Number != null) {
                        html += "<td>" + accordionJson[i].In_Number + "</td>";
                    }
                    html += "<td>" + accordionJson[i].PtActualTax + "</td>";
                    html += "<td>" + accordionJson[i].InUser + "</td>";
                    html += "</tr>";
                });

            })
            $("#accordiond").empty().append(html);
            setTimeout(function () {
                layer.closeAll(); //要延迟执行的代码块
            }, 3000);
        })
    })
    /*** 查询*/
    $(function () {
        $("#btnSearch").click(function () {
            var where = $("#where").val().trim();
            var html = "";
            getAjax("/Base/Invoice_Remake", { "where": where }, function (data) {
                var accordionJson = eval(data);
                $.each(accordionJson, function (i) {
                    html += "<tr>";
                    html += "<td hidden>" + accordionJson[i].In_Id + "</td>";
                    html += "<td><input type='checkbox' name='chk' id='" + accordionJson[i].In_Id + "' value='" + accordionJson[i].In_Id + "' ></td>";
                    html += "<td>" + accordionJson[i].Pt_CertificateNumber + "</td>";
                    html += "<td>" + accordionJson[i].Acceptance_TicketNumber + "</td>";
                    html += "<td>" + accordionJson[i].DnState + "</td>";
                    html += "<td>" + accordionJson[i].Tenant_Name + "</td>";
                    html += "<td>" + accordionJson[i].NatPer_Name + "</td>";
                    html += "<td>" + accordionJson[i].Hs_Proportion + "</td>";
                    html += "<td>" + accordionJson[i].EReviewRent + "</td>";
                    html += "<td>" + accordionJson[i].NatPer_Phone + "</td>";
                    if (accordionJson[i].In_ThreeNumber != null) {
                        html += "<td>" + accordionJson[i].In_ThreeNumber + "</td>";
                    }
                    else if (accordionJson[i].In_TwoNumber != null) {
                        html += "<td>" + accordionJson[i].In_TwoNumber + "</td>";
                    }
                    else if (accordionJson[i].In_NewNumber != null) {
                        html += "<td>" + accordionJson[i].In_NewNumber + "</td>";
                    }
                    else if (accordionJson[i].In_Number != null) {
                        html += "<td>" + accordionJson[i].In_Number + "</td>";
                    }
                    html += "<td>" + accordionJson[i].PtActualTax + "</td>";
                    html += "<td>" + accordionJson[i].InUser + "</td>";
                    html += "</tr>";
                });
            })
            $("#accordiond").empty().append(html);
        })
    })
    /*** 重录发票号*/

    $("#btnInvoice").click(function () {

        var checkId = CheckboxValueIDs();
        if (checkId.length == 0) {
            layer.msg("请选择要录入发票号的信息！");                                                             //未选中任何行
            return;
        }
        if (checkId.length > 1) {
            layer.msg("只能选择一条要录入发票号的信息！");                                                             //未选中任何行
            return;
        }
        $("#In_Number").val(getTableCell(10));
        $("#Pt_CertificateNumber").val(getTableCell(2));
        $("#Acceptance_TicketNumber").val(getTableCell(3));
        $("#Tenant_Name").val(getTableCell(5));
        $("#NatPer_Name").val(getTableCell(6));
        $("#Hs_Proportion").val(getTableCell(7));
        $("#EReviewRent").val(getTableCell(8));
        LayerOpen('750px', '320px', '录入发票号', $('#myModal'));
    });
    /*
  * 打印
  */
    $(function () {
        $("#btnPrint").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择要打印的信息！");                                                             //未选中任何行
                return;
            }
            if (checkId.length > 1) {
                layer.msg("只能选择一条信息");                                                             //未选中任何行
                return;
            }
            if (In_Number == "") {
                layer.msg("请先录入发票号，再进行打印！");
                return;

            } else {
                var In_Number = getTableCell(10);
                layer.confirm("请核对更改后的发票编号，确认是否打印? <p align='center' class='In_Numberx'>" + In_Number + "</p> ", { icon: 3, btn: ['确定', '取消'] }, function () {
                    GetPrintArea();
                    document.body.innerHTML = document.getElementById('modalPrint').innerHTML;//填充打印区域
                    window.print();//打印
                    Replace();//刷新
                })
            }
        })
    })
    /**
     *打印取值
     */
    function GetPrintArea() {
        Invoice_Get();
        if (html3 != null) {                 
            $("#In_Number_3").html("改为: " + html3);
        }
        else if (html2 != null) {
            $("#In_Number_2").html("改为: " + html2);
        }
        else if (html1 != null) {
            $("#In_Number_1").html("改为: " + html1);
        }
          
    }
    /** 刷新**/
    $(function () {
        $("#btnRefresh").click(function () {
            Replace();
        })
    })

</script>
